#include<bits/stdc++.h>
using namespace std;
double a[100005],b[100005],c[100005],d[100005];
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
    int q;
    cin>>q;
    while(q--)
    {
		int n,m,y,k,cnt=0;
		cin>>n>>m>>y>>k;
		for(int i=1;i<=n;i++)
		    cin>>a[i]>>b[i]>>c[i];
	    for(int i=1;i<=n;i++)
		    cin>>d[i];
		for(int i=1;i<=n;i++)
		{
			if(c[i]==0)
			{
				if(b[i]>k)
				{
					int w=lower_bound(d+1,d+m+1,a[i])-d;
					if(w<=n)
					{
					    cnt++;
					}
				}
				continue;
			}
            double t=a[i]+1.0*(k*k-b[i]*b[i])/(2*c[i]);
			int w=lower_bound(d+1,d+m+1,t)-d;
			if(c[i]>0) 
			{
				if(d[w]==t)w++;
				if(w<=n) 
				    cnt++;
			}
			else
			{
				w--;
				if(w>=1&&d[w]>=a[i])
				    cnt++;
			}
		}
		cout<<cnt<<" "<<1<<endl;
	}
    return 0;
}

